﻿using System;
using System.Windows.Controls;

namespace PSE.Deployment.ConfigurationManager.Controls
{
	public enum ConfigurationMessageBoxButton
	{
		Ok = 0,
		OkCancel = 1,
		YesNo = 2,
		YesNoCancel = 3
	}

	public enum ConfigurationMessageBoxResult
	{
		Ok = 0,
		Cancel = 1,
		Yes = 2,
		No = 3,
		None = 4
	}

	public enum ConfigurationMessageBoxImage
	{
		Error = 0,
		Question = 1,
		Exclamation = 2,
		Information = 3,
		None = 4
	}

	public enum ConfigurationMessageBoxState
	{
		Opened,
		Closed
	}

	public class ConfigurationMessageBox : Control
	{
		public ConfigurationMessageBoxResult Retorno { get; set; }
		const string DEFAULT_TITLE = "Configuration Manager";

		static ConfigurationMessageBox()
		{
		}

		public static ConfigurationMessageBoxResult Show(String message)
		{
			return Show(message, DEFAULT_TITLE, ConfigurationMessageBoxButton.Ok, ConfigurationMessageBoxImage.None);
		}

		public static ConfigurationMessageBoxResult Show(String message, String title)
		{
			return Show(message, title, ConfigurationMessageBoxButton.Ok, ConfigurationMessageBoxImage.None);
		}

		public static ConfigurationMessageBoxResult Show(String message, String title, ConfigurationMessageBoxButton MessageBoxButton)
		{
			return Show(message, title, MessageBoxButton, ConfigurationMessageBoxImage.None);
		}

		public static ConfigurationMessageBoxResult Show(String message, ConfigurationMessageBoxButton MessageBoxButton)
		{
			return Show(message, DEFAULT_TITLE, MessageBoxButton, ConfigurationMessageBoxImage.None);
		}

		public static ConfigurationMessageBoxResult Show(String message, String title, ConfigurationMessageBoxImage MessageBoxImage)
		{
			return Show(message, title, ConfigurationMessageBoxButton.Ok, MessageBoxImage);
		}

		public static ConfigurationMessageBoxResult Show(String message, ConfigurationMessageBoxImage MessageBoxImage)
		{
			return Show(message, DEFAULT_TITLE, ConfigurationMessageBoxButton.Ok, MessageBoxImage);
		}

		public static ConfigurationMessageBoxResult Show(String message, ConfigurationMessageBoxButton MessageBoxButton, ConfigurationMessageBoxImage MessageBoxImage)
		{
			return Show(message, DEFAULT_TITLE, MessageBoxButton, MessageBoxImage);
		}

		public static ConfigurationMessageBoxResult Show(String message, String title, ConfigurationMessageBoxButton MessageBoxButton, ConfigurationMessageBoxImage MessageBoxImage)
		{
			return Show(message, title, MessageBoxButton, MessageBoxImage, null, null);
		}

		public static ConfigurationMessageBoxResult Show(String message, String title, ConfigurationMessageBoxButton MessageBoxButton, ConfigurationMessageBoxImage MessageBoxImage, double? windowHeight, double? windowWidth)
		{
			ConfigurationMessageBoxWindow msg = new ConfigurationMessageBoxWindow(message, title, MessageBoxButton, MessageBoxImage, windowHeight, windowWidth);
			ConfigurationMessageBoxResult result;

			if (OnMessageBoxStateChanged != null)
				OnMessageBoxStateChanged(ConfigurationMessageBoxState.Opened);

			//System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(new Action(delegate() { msg.ShowDialog(); }), null);
			msg.ShowDialog();

			result = msg.Retorno;

			if (OnMessageBoxStateChanged != null)
				OnMessageBoxStateChanged(ConfigurationMessageBoxState.Closed);

			msg = null;

			return result;
		}

		public delegate void OnMessageBoxStateChangedEventHandler(ConfigurationMessageBoxState state);
		public static event OnMessageBoxStateChangedEventHandler OnMessageBoxStateChanged;
	}
}